// 用户
const mongoose = require('mongoose')
const usersSchema = new mongoose.Schema({
    // mongoose默认产生的字段，不需要展示
    __v: {
        type: Number,
        select: false
    },
    // 用户名
    name: {
        type: String,
        required: true
    },
    // 密码
    password: {
        type: String,
        required: true,
        //不应该显示密码，TODO
        select: true 
    },
    // 头像
    avatar_url: {
        type: String,
        default: null
    },
    // 性别
    gender: {
        type: String,
        //枚举，只能是这两个值
        enum: ['male', 'female'],
        default: 'male'
    },
    // 一句话介绍
    headline: {
        type: String,
        default: null
    },


    // 关注的用户列表 
    // 与用户的Schema关联，通过populate把following替换为Users对象
    following: {
        type: [{
            type: mongoose.Schema.Types.ObjectId,
            ref: 'Users',//关注的id是和用户相关联的
        }],
        select: false
    },


    // 关注的话题列表 
    // 用户-话题多对多关系
    // 与话题的Schema关联，通过populate把followingTopics替换为Topics对象
    followingTopics: {
        type: [{
            type: mongoose.Schema.Types.ObjectId,
            ref: 'Topics',
        }],
        select: false
    },


    // 答案互斥关系的赞/踩答案
    // 点赞答案列表
    likingAnswers: {
        type: [{
            type: mongoose.Schema.Types.ObjectId,
            ref: 'Answers'
        }],
        select: false
    },
    // 点踩答案列表
    dislikingAnswers: {
        type: [{
            type: mongoose.Schema.Types.ObjectId,
            ref: 'Answers'
        }],
        select: false
    },

    // 收藏答案列表
    collectingAnswers: {
        type: [{
            type: mongoose.Schema.Types.ObjectId,
            ref: 'Answers'
        }],
        select: false
    },



    // 居住地 与话题的Schema关联，通过populate把locations替换为Topics对象
    // locations:{type:[{type:String}],select:false}
    locations: {
        type: [{
            type: mongoose.Schema.Types.ObjectId,
            ref: 'Topics'
        }],
        select: false
    },
    // 所在行业 与话题的Schema关联，通过populate把business替换为Topics对象
    business: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Topics',
        default: null,
        select: false
    },
    // 职业经历 与话题的Schema关联，通过populate把employments里面的company、job替换为Topics对象
    // employments:{type:[{company:{type:String},job:{type:String}}]}
    employments: {
        type: [{
            company: {
                type: mongoose.Schema.Types.ObjectId,
                ref: 'Topics'
            },
            job: {
                type: mongoose.Schema.Types.ObjectId,
                ref: 'Topics'
            }
        }],
        select: false
    },
    // 教育经历 与话题的Schema关联，通过populate把educations里面的school、major替换为Topics对象
    educations: {
        type: [{
            // 学校
            school: {
                type: mongoose.Schema.Types.ObjectId,
                ref: 'Topics'
            },
            // 专业
            major: {
                type: mongoose.Schema.Types.ObjectId,
                ref: 'Topics'
            },
            // 学历 1高中及以下 2大专 3本科 4硕士 5博士及以上
            diploma: {type: Number, enum: [1, 2, 3, 4, 5]},
            // 时间
            entrance_year: {type: Number},
            graduation_year: {type: Number},
        }],
        select: false
    },



    // 商城
    // 订单列表
    orderList: {
        type: [{
            type: mongoose.Schema.Types.ObjectId,
            ref: 'OrderList'
        }]
    },

    cartList: {
        type: [{
            type: mongoose.Schema.Types.ObjectId,
            ref: 'cartList'
        }]
    },
    // 收货地址
    addressList: {
        type: [{
            type: mongoose.Schema.Types.ObjectId,
            ref: 'addressList'
        }]
    },

}, {timestamps: true})
module.exports = mongoose.model('Users', usersSchema)
